#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc2_r12_aux_ch4_sym_pol.info <<'%EOF%'
   cc2_r12_aux_ch4_sym_pol
   -------------
   Molecule:         Methane (CH4)
   Wave Function:    CC2-R12 / 6-311G**
   Test Purpose:     - Check CC2-R12 response with symmetry
                     - non-direct mode
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > cc2_r12_aux_ch4_sym_pol.mol <<'%EOF%'
BASIS
6-311G** 6-311++G(3df,3pd)
CC2-R12/A response using symmetry

    4    2 XY XZ
 1      6.    1
C      0.000000000000000   0.000000000000000   0.000000000000000       *
 1      1.    1
H      1.276731000000000   1.276731000000000   1.276731000000000       *
 2      6.    1
C      0.000000000000000   0.000000000000000   0.000000000000000       *
 2      1.    1
H      1.276731000000000   1.276731000000000   1.276731000000000       *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc2_r12_aux_ch4_sym_pol.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
*MOLBAS
.R12AUX
**INTEGRALS
.R12
.DIPLEN
**WAVE FUNCTIONS
.CC
*SCF INPUT
.THRESHOLD
 1.0D-10
*ORBITALS
.MOSTART
 H1DIAG
*CC INPUT
.CC2
.PRINT
 3
.FREEZE
 1 0
.THRENR
 1.0D-14
.THRLEQ
 1.0D-12
.PACK
 1.0D-15
*CCLR
.AVERAG
ALPHA_ANI
GENER
*CCQR
.AVERAG
HYPERPOL
*CCCR
.AVERAG
GAMMA_ISO
GENER
*R12 INPUT
.CC2
 1A
**END OF DALTON INPUT
%EOF%

#######################################################################
 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc2_r12_aux_ch4_sym_pol.check
cat >>cc2_r12_aux_ch4_sym_pol.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#
#            Total SCF   energy:                   -40.1917720926
#            Total MP2-R12/A energy:               -40.3918078442
#            Total CC2-R12/A energy:               -40.3929123948
#

CRIT1=`$GREP "Total MP2-R12/A energy: *\-40\.391807844" $log | wc -l`
TEST[1]=`expr   $CRIT1`
CTRL[1]=2
ERROR[1]="MP2-R12/A ENERGY NOT CORRECT"
CRIT2=`$GREP "Total CC2-R12/A energy: *\-40\.392912394" $log | wc -l`
TEST[2]=`expr   $CRIT2`
CTRL[2]=2
ERROR[2]="CC2-R12/A ENERGY NOT CORRECT"
#
CRIT31=`$GREP "XDIPLEN *\(unrel.\) *( |0)\.0000 *15\.514431" $log | wc -l`
CRIT32=`$GREP "YDIPLEN *\(unrel.\) *( |0)\.0000 *15\.514431" $log | wc -l`
CRIT33=`$GREP "ZDIPLEN *\(unrel.\) *( |0)\.0000 *15\.514431" $log | wc -l`
TEST[3]=`expr $CRIT31 + $CRIT32 + $CRIT33`
CTRL[3]=3
ERROR[3]="CC2-R12/A POLARIZABILITY NOT CORRECT"
CRIT41=`$GREP "beta_\|\| *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000000" $log | wc -l`
CRIT42=`$GREP "beta_\|_ *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000000" $log | wc -l`
CRIT43=`$GREP "beta\^K *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000000" $log | wc -l`
CRIT44=`$GREP "beta_ms *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000000" $log | wc -l`
TEST[4]=`expr $CRIT41 + $CRIT42 + $CRIT43 + $CRIT44`
CTRL[4]=4
ERROR[4]="CC2-R12/A FIRST HYPERPOLARIZABILITY NOT CORRECT"
CRIT51=`$GREP "gamma_\|\| *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0)\.0000 *\-751\.93936" $log | wc -l`
CRIT52=`$GREP "gamma_\|_ *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0|\-0|\-)\.0000 *( |0)\.0000 *\-250\.64645" $log | wc -l`
CRIT53=`$GREP "gamma_ms *\-*0*\.0000 *\-*0*\.0000 *\-*0*\.0000 *\-*0*\.0000 *\-*0*\.0000000" $log | wc -l`
TEST[5]=`expr $CRIT51 + $CRIT52 + $CRIT53`
CTRL[5]=3
ERROR[5]="CC2-R12/A SECOND HYPERPOLARIZABILITY NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
